//
//  UIImage+Extension.swift
//  weiboZY
//
//  Created by 赵勇 on 16/5/20.
//  Copyright © 2016年 赵勇. All rights reserved.
//

import UIKit


extension UIImage {
    
    
    // 等比压缩图片的方法
    func scaleImageWithWidth( scaleWidth: CGFloat) -> UIImage {
        
        let scaleHeight = scaleWidth / self.size.width * self.size.height
        
        let size = CGSize(width: scaleWidth, height: scaleHeight)
        
        // 开启图形上下文
        UIGraphicsBeginImageContext(size)
        
        self.drawInRect(CGRect(origin: CGPointZero, size: size))
        
        // 获得压缩后的图片
        let scaleImage = UIGraphicsGetImageFromCurrentImageContext()
        
        // 关闭图形上下文
        UIGraphicsEndImageContext()
        
        return scaleImage
    }
    
    
    
    
}


